package com.hbnu.servlet;

import javax.servlet.*;
import java.io.IOException;

/**
 * @author kittychen
 * @since 2025-11-03 16:29
 */
public class MyServletDemo01 implements Servlet {
    @Override
    public void init(ServletConfig servletConfig) throws ServletException {
        System.out.println("创建Servlet实例对象的时候调用，主要用于Servlet对象的初始化");
        String name = servletConfig.getInitParameter("name");
        String age = servletConfig.getInitParameter("age");
        System.out.println("Servlet初始化参数：name=" + name + ",age=" + age);
        ServletContext servletContext = servletConfig.getServletContext();  // 获取ServletContext对象
    }

    @Override
    public ServletConfig getServletConfig() {
        return null;
    }

    @Override
    public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException {
        servletResponse.getWriter().write("Hello Servlet");
    }

    @Override
    public String getServletInfo() {
        return "";
    }

    @Override
    public void destroy() {
        System.out.println("Servlet对象销毁的时候调用，主要用于Servlet对象的销毁");
    }
}
